package com.shiikong_memory.yez.ReadWorld;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.shiikong_memory.yez.KOOKBasics.Broadcast;
import com.shiikong_memory.yez.Tool.ListStore;
import love.forte.simbot.application.Application;
import love.forte.simbot.bot.BotManager;
import love.forte.simbot.bot.BotManagers;
import love.forte.simbot.common.id.Identifies;
import love.forte.simbot.component.kook.KookChatChannel;
import love.forte.simbot.component.kook.KookGuild;
import love.forte.simbot.component.kook.bot.KookBot;
import love.forte.simbot.component.kook.bot.KookBotManager;
import love.forte.simbot.component.kook.event.KookChannelMessageEvent;
import love.forte.simbot.quantcat.common.annotations.ContentTrim;
import love.forte.simbot.quantcat.common.annotations.Listener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.io.*;
import java.util.List;

@Component
public class ReadWorld {
    @Autowired
    Broadcast broadcast;

    @Autowired
    private Application application;

    @Autowired
    private RestTemplate restTemplate;
    private static List<String> ChannelList;
    static {
        try {
            ChannelList = ListStore.readList("./60ReadWorld.txt");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Scheduled(cron="0 0 12 * * ?")
    public void Timing(){
        ResponseEntity<String> results = restTemplate.exchange("https://api.jun.la/60s.php?format=imgapi", HttpMethod.GET, null, String.class);
        JSONObject jsonObject = JSON.parseObject(results.getBody());
        String title = jsonObject.getString("imageTime");
        String IMGUrl = jsonObject.getString("imageBaidu");
        //发送
        broadcast.senndAllMessage(10,Json.formatted(title, IMGUrl));
    }

    private static String Json = """
            [
              {
                "type": "card",
                "theme": "secondary",
                "size": "lg",
                "modules": [
                  {
                    "type": "header",
                    "text": {
                      "type": "plain-text",
                      "content": "每天60秒读懂世界   %s"
                    }
                  },
                  {
                    "type": "divider"
                  },
                  {
                    "type": "container",
                    "elements": [
                      {
                        "type": "image",
                        "src": "%s"
                      }
                    ]
                  }
                ]
              }
            ]
            """;
}
